//main.cpp
/*    widgetpp - A simple C++ wrapper of DISLIN graphic library               */
/*                                                                            */
/*    Copyright (C) 2012  Mirko Cambi (email: mirko.cambi@gmail.com)          */
/*                                                                            */
/*    This program is free software: you can redistribute it and/or modify    */
/*    it under the terms of the GNU General Public License as published by    */
/*    the Free Software Foundation, either version 3 of the License, or       */
/*    (at your option) any later version.                                     */
/*                                                                            */
/*    This program is distributed in the hope that it will be useful,         */
/*    but WITHOUT ANY WARRANTY; without even the implied warranty of          */
/*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           */
/*    GNU General Public License for more details.                            */
/*                                                                            */
/*    You should have received a copy of the GNU General Public License       */
/*    along with this program.  If not, see <http://www.gnu.org/licenses/>.   */

#include <cctype>
#include <boost/config.hpp>
#include <boost/shared_ptr.hpp>

#include "Widgetpps.hpp"

using namespace wdgpp;

class MyWidgetpp: public Widgetpp
{
public:
   MyWidgetpp(): Widgetpp("Prova wrapper", -40, laid_out::hori)
   {
   }

   void change_label(int id)
   {
      std::string selected = get_widget<WdgDList>("dlist")->get_selected();
      get_widget<WdgLabel>("label")->set_label(selected);
   }

   void uppercase(int id)
   {
      std::string selected = get_widget<WdgDList>("dlist")->get_selected();
      if(get_widget<WdgCheckButton>("check_button")->get_status())
         std::transform(selected.begin(), selected.end(), selected.begin(), std::toupper);
      else
         std::transform(selected.begin(), selected.end(), selected.begin(), std::tolower);

      get_widget<WdgLabel>("label")->set_label(selected);
   }

   void button_click(int id)
   {
      wdgpp::WdgMessageDlg("Button pressed");
   }

   void init()
   {
      int p0 = add("panel0", new WdgContainer(laid_out::vert));
      int p1 = add("panel1", new WdgContainer(laid_out::vert));

      items.resize(3);
      items[0] = "pippo";
      items[1] = "pluto";
      items[2] = "paperino";
      std::string list = items[0] + "|" + items[1] + "|" + items[2];

      label_id = add("label", new WdgLabel("Prova."), p0);      
      dlist_id = add("dlist", new WdgDList(list, 2), p0);
      checkbutton_id = add("check_button", new WdgCheckButton("Upper case.", 0), p0);
      button_id = add("button", new WdgButton("Button"), p1);
      add("scale", new WdgScale("Scale", 0, 100, 50, 0), p1);
      add("box", new WdgCheckBox(list, 2), p1);
      add("text", new WdgText("Prova testo"), p1);

      int draw_id = add("draw", new WdgDraw(), p0);
   
      Wdg2DPlot w2p;
      w2p.init(draw_id, 3000, 3000);
      w2p.erase();
      w2p.set_position(250,2750);
      w2p.set_lenght(2500,2500);
      w2p.cartesian_axis(-0.5, 0.5, -0.5, 0.1, -0.5, 0.5, -0.5, 0.1);
      w2p.close();

      register_callback(dlist_id, &MyWidgetpp::change_label);
      register_callback(checkbutton_id, &MyWidgetpp::uppercase);
      register_callback(button_id, &MyWidgetpp::button_click);
   }

private:
   int label_id;
   int dlist_id;
   int checkbutton_id;
   int button_id;
   std::vector<std::string> items;
};

int main()
{
   MyWidgetpp w;
   w.init();
   w.draw();

   return 0;
}

